//版本四
//更符合直接理解
const traffic = document.getElementById('traffic');

function wait(time) {
    return new Promise(resolve => setTimeout(resolve, time))
}

function setState(state) {
    traffic.className = state;
}

async function start() {
    while (1) {
        setState('s1');
        await wait(500)
        setState('s2');
        await wait(500)
        setState('s3');
        await wait(500)
    }
}
start();